home *** CD-ROM | disk | FTP | other *** search
- Path: andrew.cmu.edu!mp52+
- From: Matthew Edward Patton <mp52+@andrew.cmu.edu>
- Newsgroups: comp.lang.c++
- Subject: template classes and destructors
- Date: Mon, 11 Mar 1996 00:35:01 -0500
- Organization: Civil and Environmental Engineering, Carnegie Mellon, Pittsburgh, PA
- Message-ID: <4lEvi5m00iVGA_jM06@andrew.cmu.edu>
- NNTP-Posting-Host: po8.andrew.cmu.edu
-
- I have a template based class:
- template <class T>
- class foo {
- T value;
- public:
- foo() { value = (T) 0; }
- foo(int size) { value = (T) 0; }
- ~foo() { ::delete() };
- };
-
- foo<char*>::foo(int size) { value = new char[size]; }
-
- I need to override the default behavior of the constructors only when
- the type is <char*>. That works. The deconstructor needs to be defined
- only for the <char*> class, since all other types don't care. If I
- don't have a destuctor I have a memory leak do I not?
-
- I followed the same syntax as the overridden constructors and declared:
- foo<char*>::~foo() { delete[] value; }
-
- This always gives me an error saying a member function 'foo' hasn't been
- defined for class foo<char*>. The error is 'ridiculous' as I can point
- to 2 very much working constructors for class field<char*>.
-
- Can anyone shed someight on this? thans very much
-
-